-
Notifications
You must be signed in to change notification settings - Fork 30
fix: merge transaction context into hook context evaluation context (#521) #523
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
@thomaspoignant would be interested in your opinion on the "Notes" section above. |
6f9176c to
13d0f92
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #523 +/- ##
==========================================
+ Coverage 97.65% 97.85% +0.19%
==========================================
Files 37 38 +1
Lines 1788 1814 +26
==========================================
+ Hits 1746 1775 +29
+ Misses 42 39 -3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Hey @kouk, are you updating the transaction context in a before hook? You should be able to return additional context from the before hook. You can see how that work in JS. You're correct that we don't re-evaluate the transaction context after the before hook but it shouldn't be necessary because of the feature I mentioned above. |
|
@beeme1mr AFAICT the python sdk does not do what the JS sdk does. Here's the relevant part of the JS sdk: https://github.com/open-feature/js-sdk/blob/d8bd93b6d5256445d12185d639e1cd91800a8a16/packages/server/src/client/internal/open-feature-client.ts#L329 OTOH the Python SDK does not do this:
This PR does not currently change this, so there is a discrepancy IMHO between the JS and Python SDKs in this regard. I could update this PR or create a new one to address this discrepancy. |
|
Changes look okay from my end, please address the linting.
From a consumer, that behaviour is expected but it should be decided by the spec. |
4378d1d to
f08fa5f
Compare
gruebel
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, nice work 🍻 left a small comment
|
Opened two issues in the spec repo: |
…pen-feature#521) Signed-off-by: Konstantinos Koukopoulos <[email protected]>
56e968e to
5ce432f
Compare
|
@leohoare it occurred to me after reading your comment that the current fix is also not something that is explicitly specified by the spec. Although it seems pretty obvious to me perhaps the spec could be updated to say this explicitly: open-feature/spec#328 |
merge transaction context into hook context evaluation context
Currently during flag evaluation the transaction context is merged into the evaluation context here:
python-sdk/openfeature/client.py
Line 778 in 288bd6b
However the
hook_context.evaluation_contextis created before this, so it doesn't contain the attributes or targeting key that exists in the propagated transaction context. This is unexpected. It is also different than what the JS implementation does.In this PR:
_establish_hooks_and_providerbefore creating the hook context._before_hooks_and_merge_contextmethod is renamed as_run_before_hooks_and_update_contextto better reflect its updated functionality which is now restricted to just adding the before hooks results to the context._run_before_hooks_and_update_contextwhich was inaptly named IMHO. The result of the before hooks is not the "invocation context".This ensures that hooks have access to the complete evaluation context, including any attributes or targeting key from the transaction context.
Related Issues
Fixes #521
Notes
Currently, both the Python sdk and the JS sdk do not update the hook context's
evaluation_contextfield after running the before hooks. This is not explicitly required by the spec here: https://openfeature.dev/specification/sections/evaluation-context/#requirement-323or here:
https://openfeature.dev/specification/sections/hooks
However it seems to me to be a safe assumption that if the before hooks update the evaluation context then the hook context should reference this updated evaluation context instead of referencing the evaluation context as it was before the before hooks ran. I can open a different issue about this